package edu.sctu.zcy.month201506.day20150618.httptest;

import java.io.*;

import java.net.*;



public class HttpRequestPost {

   private PrintWriter printWriter;

    public void setPost(String url,String params) {



        byte[] bytes = new byte[1024];
        try {
            URL url1 = new URL(url);

            HttpURLConnection httpURLConnection = (HttpURLConnection) url1.openConnection();

            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setDoInput(true);
            httpURLConnection.setDoOutput(true);

            httpURLConnection.connect();

            OutputStream outputStream = httpURLConnection.getOutputStream();
            outputStream.write(params.getBytes());

            outputStream.close();

//            printWriter.print(params.getBytes());


            InputStream inputStream = httpURLConnection.getInputStream();

            int line;
            while ((line = inputStream.read(bytes)) != -1){
                System.out.println(new String(bytes,0,line));
            }


        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }


}
